import logging

logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
# 文件处理器
ch = logging.FileHandler(filename='mylog.log', encoding="utf-8")
ch.setLevel(logging.DEBUG)
# create formatter
# 定义格式器
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)